package sample.multithread.service;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

/**
 * @author : dongyz8
 * @Date : 2023/11/20 9:21
 **/
public class Service {

    /**
     * 创建线程池示例代码
     */
    public void example1(){
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("thread-gplmCallBack-runner-%d").build();
        ExecutorService executor = new ThreadPoolExecutor(1, 10, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(), namedThreadFactory);
        executor.submit(() -> {
            // 需要多线程执行的代码...
        });
    }
}
